package com.example.demo6.Controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.example.demo6.Service.IBannerService;
import com.example.demo6.entity.Banner;
import com.example.demo6.utils.PageResult;
import com.example.demo6.utils.PassToken;
import com.example.demo6.utils.ServerResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * bannerController
 * 
 * @author ruoyi
 * @date 2025-03-27
 */
@RestController
@RequestMapping("/system/banner")
public class BannerController
{
    @Autowired
    private IBannerService bannerService;

    /**
     * 查询banner列表
     */
    @PassToken
    @GetMapping("/list")
    public ServerResponse list(Banner banner, @RequestParam(defaultValue = "1") int pageNum,  @RequestParam(defaultValue = "4")int pageSize)
    {
//        startPage();
        PageResult pageResult=bannerService.selectBannerList(banner,pageNum,pageSize);
        return ServerResponse.createBySuccess(200,pageResult,"查询成功");
    }

    /**
     * 导出banner列表
     */
//    @PreAuthorize("@ss.hasPermi('system:banner:export')")
//    @Log(title = "banner", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, Banner banner)
//    {
//        List<Banner> list = bannerService.selectBannerList(banner);
//        ExcelUtil<Banner> util = new ExcelUtil<Banner>(Banner.class);
//        util.exportExcel(response, list, "banner数据");
//    }

    /**
     * 获取banner详细信息
     */
    @GetMapping(value = "/{id}")
    public ServerResponse getInfo(@PathVariable("id") Long id)
    {
Banner banner=bannerService.selectBannerById(id);
            return ServerResponse.createBySuccess(200,banner,"查询成功");

    }

    /**
     * 新增banner
     */
    @PostMapping
    public ServerResponse add(@RequestBody Banner banner)
    {
        int i=bannerService.insertBanner(banner);
        if(i>0){
            return ServerResponse.createBySuccess(200,"","添加成功");
        }else{
            return ServerResponse.createByFail(500,"添加失败");
        }
    }

    /**
     * 修改banner
     */
    @PutMapping
    public ServerResponse edit(@RequestBody Banner banner)
    {
        int i=bannerService.updateBanner(banner);
        if(i>0){
            return ServerResponse.createBySuccess(200,"","更新成功");
        }else{
            return ServerResponse.createByFail(500,"更新失败");
        }
    }

    /**
     * 删除banner
     */

	@DeleteMapping("/{ids}")
    public ServerResponse remove(@PathVariable Long[] ids)
    {
        int i=bannerService.deleteBannerByIds(ids);
        if(i>0){
            return ServerResponse.createBySuccess(200,"","删除成功");
        }else{
            return ServerResponse.createByFail(500,"删除失败");
        }

    }
}
